//
//  WachInfoViewController.m
//  leo
//
//  Created by 常艳 on 15/11/6.
//  Copyright (c) 2015年 mdx. All rights reserved.
//

#import "WachInfoViewController.h"
#import "BindViewController.h"
#import "ChooseRelationViewController.h"
@interface WachInfoViewController ()
@property(nonatomic,strong) NSString *sim;
@end

@implementation WachInfoViewController
-(void)dealloc
{
    self.sim=NULL;
    self.scanView=NULL;
    self.watch=NULL;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.extendedLayoutIncludesOpaqueBars=YES;
    self.title=@"手表信息";
    UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"Back_icon@2x.png"] style:UIBarButtonItemStylePlain target:self action:@selector(back)];
    [self.navigationItem setLeftBarButtonItem:leftButton];
    self.navigationItem.leftItemsSupplementBackButton=NO;
    float rate=[UIScreen mainScreen].bounds.size.width/375;
    float x=self.imeiText.frame.size.height;
    UIView *imeileftView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 120*rate, x)];
    self.imeiText.leftView=imeileftView;
    self.imeiText.leftViewMode=UITextFieldViewModeAlways;
    UIView *simleftView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 120*rate,x)];
    self.simText.leftView=simleftView;
    self.simText.leftViewMode=UITextFieldViewModeAlways;
    if(self.watch==NULL)
    {
        NSLog(@"%@,viewDidLoad,watch is null.",WatchInfo_tag);
        [LeoMsg showMsg:@"扫描手表二维码失败"];
        BindViewController *bindView=[[BindViewController alloc] init];
        bindView.type=1;
        [self.navigationController pushViewController:bindView animated:YES];
    }
    if(self.watch.imei!=NULL&&![self.watch.imei isEqualToString:@"(null)"])
    {
        self.imeiText.text=self.watch.imei;
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    if(self.view.window==nil)
    {
        self.view=nil;
    }
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (IBAction)next:(id)sender {
    self.sim=self.simText.text;
    self.sim=[self.sim stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
    if(self.sim==NULL||[self.sim length]<=0)
    {
        [LeoMsg showMsg:@"请输入手表SIM卡号"];
        return;
    }
    self.watch.sim=self.sim;
    //跳转选择关系界面
    ChooseRelationViewController *chooseRelation=[[ChooseRelationViewController alloc] init];
    chooseRelation.watch=self.watch;
    [self.navigationController pushViewController:chooseRelation animated:YES];
}
- (void)back {
    if(self.scanView!=NULL)
    {
        [self.scanView startReading];
    }
    [self.navigationController popViewControllerAnimated:YES];
}
- (IBAction)backgroundTap:(id)sender {
    [self.imeiText resignFirstResponder];
    [self.simText resignFirstResponder];
}

@end
